﻿using BussinessObject.ObjectTwo;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ProjectHK3.App_Code;
namespace ProjectHK3.Object_One
{
    public partial class Login : System.Web.UI.Page
    {
        B_Login ex = new B_Login();
        DataTable tb = new DataTable();
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Session.Clear();
            }
        }
          
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ex.checkLogin(TextBox1.Text, TextBox2.Text).ToString() == "True")
            {
                tb = ex.Login(TextBox1.Text, TextBox2.Text);
                if (tb.Rows.Count > 0)
                {
                    if (tb.Rows[0]["Role"].ToString() == "1")
                    {
                        Session["Admin"] = TextBox1.Text.Trim();
                        Response.Redirect("AdminHome.aspx");
                        
                    }
                    else
                    {
                        Session["User"] = TextBox1.Text.Trim();
                        Response.Redirect("../ObjectTwo/Home.aspx");
                        
                    }
                }
                else
                {
                    TextBox2.Text = "";
                   Alert.Show("Incorrect Username or Password");
                   

                }
                Alert.Show("Incorrect Username or Password");
            }
        }

      

       
    }
}